const {PrismaClient} = require('@prisma/client');

const prisma = new PrismaClient({
    log: ['query', 'info', 'warn']
});


const getVerifyCodeByPhone = (phone) => {
    return prisma.loginPhone.findFirst({
        where: {
            phone,
            isDeleted: 0,
            createTime: {
                gt: new Date(new Date().getTime() - 1000 * 60)
            }
        },
        orderBy: {
            createTime: 'desc'
        },
    })
}

const createVerifyCode = (phone, code) => {
    return prisma.loginPhone.create({
        data: {
            phone,
            code
        }
    })
}

module.exports = {
    getVerifyCodeByPhone,
    createVerifyCode
}